ST558-651 Project 1

Set Up Data Scrape

Get List of Teams

Check Team ID

Functions

Record Functions

Stat Functions

Wrapper Function

Summarizing

Playoffs by Total Games Played

#let's look at all franchises via franchise totals
data <- get_nhl_data('Franchise Totals')

#let's look at active franchises first
#and pivot wider so that playoffs and reg season 
#are on the same line of data
franchises <- data %>% filter(activeFranchise == 1) %>%
                mutate(game_type = if_else(gameTypeId == 2, 
                                           'regular', 'playoff')) %>%
                select(franchiseId, teamName, gamesPlayed, 
                       wins, losses, game_type) %>%
                pivot_wider(names_from = game_type, values_from = 
                              c(gamesPlayed, wins, losses))


franchises$win_pct_playoff <- franchises$wins_playoff / 
                        (franchises$wins_playoff + franchises$losses_playoff)

g <- ggplot(data=franchises, aes(x=gamesPlayed_regular, y=win_pct_playoff)) +
      geom_point(aes(name=teamName))
## Warning: Ignoring unknown aesthetics: name
p <- ggplotly(g)